FROM golang:1.24.4 AS build

COPY openEuler.repo /etc/yum.repos.d/openEuler.repo

RUN set -eux; \
    dnf install -y git glibc-all-langpacks && dnf clean all

ARG ETCD_VERSION=3.6.1

RUN set -eux; \
    git clone -b v3.6.1 https://gitcode.com/gh_mirrors/et/etcd.git /etcd-src && \
    cd /etcd-src && \
    ./scripts/build.sh

FROM openeuler-22.03-lts-sp4:latest

COPY gosu-arm64 /usr/local/bin/gosu
COPY openEuler.repo /etc/yum.repos.d/openEuler.repo
COPY --from=build /etcd-src/bin/etcd /usr/local/bin/etcd
COPY --from=build /etcd-src/bin/etcdctl /usr/local/bin/etcdctl
COPY --from=build /etcd-src/bin/etcdutl /usr/local/bin/etcdutl

ENV GOSU_VERSION 1.17
RUN set -eux; \
    chmod +x /usr/local/bin/gosu

RUN set -eux; \
    dnf install -y glibc-all-langpacks && dnf clean all

RUN set -eux; \
    groupadd -g 70 etcd; \
    useradd -r -u 70 -g etcd -m -d /home/etcd etcd; \
    mkdir -p /home/etcd/instance; \
    chown -R etcd:etcd /home/etcd/instance

COPY conf/config.yaml /home/etcd/config.yaml.template

ENV LANG en_US.UTF-8
EXPOSE 2379 2380
VOLUME ["/home/etcd/instance"]

COPY entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/entrypoint.sh; \
    ln -sf /usr/local/bin/entrypoint.sh / # backwards compat

ENTRYPOINT ["entrypoint.sh"]
CMD ["etcd", "--config-file", "/home/etcd/instance/config.yaml"]

STOPSIGNAL SIGQUIT
